<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
      xmlns:h="http://xmlns.jcp.org/jsf/html">

    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <link rel="shortcut icon" type="image/x-icon" href="#{publicFields.icon}"/>
        <title>
            #{messages.SystemNameRef}
        </title>
        <h:outputStylesheet library="css" name="jsfcrud.css"/>
        <h:outputScript library="javaScript" name="markdown-it.min.js" target="head"/>
    </h:head>

    <h:body>   
        <div style="background-color: #6666ff;">
            <ui:insert name="title">Default Title</ui:insert>
        </div>
        <p>
            <ui:insert name="body">Default Body</ui:insert>
        </p>
        
            <script>
        function convertMarkdown() {
            const md = new window.markdownit({
                html: true,
                linkify: true
            });

            const input = document.getElementById('markdown-input').value;
            const output = md.render(input);

            // 清空旧输出并添加新输出  
            document.getElementById('markdown-output').innerHTML = output;
            const mathNeed2Scan=document.getElementById('markdown-output');
            MathJax.typesetPromise([mathNeed2Scan]);
        }  
    </script>
    <script>
        document.addEventListener("DOMContentLoaded", function (event) {
            // 动态创建 MathJax 配置脚本  
            const mathjaxScript = document.createElement('script');
            mathjaxScript.type = 'text/x-mathjax-config';
            mathjaxScript.async = true;
            mathjaxScript.textContent = `  
        MathJax.Hub.Config({  
          tex2jax: {  
            inlineMath: [['$','$'], ['\\(','\\)']],  
            displayMath: [['$$','$$'], ['\\[','\\]']],  
            processEscapes: true  
          },  
          "HTML-CSS": {  
            preferredFont: "TeX",  
            availableFonts: ["STIX","TeX"],  
            linebreaks: {  
              automatic: true  
            }  
          },  
          SVG: {  
            linebreaks: {  
              automatic: true  
            }  
          },  
          CommonHTML: {  
            linebreaks: {  
              automatic: true  
            }  
          },  
          TeX: {  
            extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]  
          },  
          messageStyle: "none"  
        });  
      `;

            // 将 MathJax 配置脚本添加到页面 
            if (null === document.getElementsByName('MathJax.Hub.Config'))
                document.head.appendChild(mathjaxScript);
            // 加载 MathJax 脚本  
            const mathjax = document.createElement('script');
            mathjax.src = "https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js";
            mathjax.async = true;

            // 将 MathJax 脚本添加到页面  
            document.head.appendChild(mathjax);
        });
    </script>
    </h:body>

</html>
